package com.sun.showcase.controller.testcase;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.showcase.biz.testcase.service.TestTaskService;
import com.sun.showcase.client.testcase.domain.TestTask;
import com.sun.showcase.client.testcase.query.TestTaskQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Json;

@Controller
@RequestMapping(value="/testcase/testTask") 
public class TestTaskController{
	
	@Autowired
	private TestTaskService testTaskService;
	
	private Json json = new Json();
	/**
	 * 跳转到TestTask管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goTestTask")
	public String goTestTask() {
		return "testcase/testTask";
	}
	/**
	 * 跳转到TestTask新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleTestTask")
	public String handleTestTask(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "testcase/testTask_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public TestTask showDesc(TestTaskQuery testTaskQuery) {
		return testTaskService.get(testTaskQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(TestTaskQuery testTaskQuery) {
		return testTaskService.datagrid(testTaskQuery);
	}
	
	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/listAll")
	public List<TestTaskQuery> listAll(TestTaskQuery testTaskQuery) {
		return testTaskService.listAll(testTaskQuery);
	}
	

	/**
	 * 添加一个TestTask
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Json add(TestTaskQuery testTaskQuery) {
		testTaskService.add(testTaskQuery);
		json.setSuccess(true);
		json.setMsg("添加成功！");
		return json;
	}

	/**
	 * 编辑TestTask
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Json edit(TestTaskQuery testTaskQuery) {
		testTaskService.update(testTaskQuery);
		json.setSuccess(true);
		json.setMsg("编辑成功！");
		return json;
	}

	/**
	 * 物理删除TestTask
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Json delete(TestTaskQuery testTaskQuery) {
		testTaskService.delete(testTaskQuery.getIds());
		json.setSuccess(true);
		json.setMsg("删除成功！");
		return json;
	}
	
	/**
	 * 逻辑删除TestTask
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Json deletePt(TestTaskQuery testTaskQuery) {
		testTaskService.deletePt(testTaskQuery.getIds());
		json.setSuccess(true);
		json.setMsg("删除成功！");
		return json;
	}
	/**
	 * 逻辑删除TestTask
	 */
	@ResponseBody
	@RequestMapping(value="getAllCount")
	public TestTaskQuery getAllCount(TestTaskQuery testTaskQuery) {
		testTaskService.getAllCount(testTaskQuery);
		return testTaskQuery;
	}
}
